package com.alan.server2;

import com.alan.server2.config.QjxFeignLogger;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import feign.Feign;
import feign.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * Created by Alan on 17-8-22
 */
@EnableAutoConfiguration
@Configuration
@SpringBootApplication
@EnableDiscoveryClient          //通过该注解，实现服务发现，注册
@EnableHystrix                  //启动Hystrix 会有hystrix.stream接口,用于监控
//@EnableHystrixDashboard         //启用Hystrix Dashboard（仪表盘）功能
@EnableFeignClients             //启用注解请求
@EnableCircuitBreaker           //开启断路器功能
public class Server2Application {

    public static void main(String[] args) {
        SpringApplication.run(Server2Application.class, args);
    }


    /**
     * 注入该bean 则负载均衡是为随机的（默认是轮询的）
     * @return
     */
//    @Bean
    public IRule ruibbonRule(){
        return new RandomRule();
    }

    /**
     * 添加feign日志，让其输出(是以debug输出的)，并在logback中给对应的包（项目中用到freign的）设置为DEBUG。则可看到相应请求日志
     * @return
     */
    @Bean
    Logger.Level feignLevel(){
        return Logger.Level.FULL;
    }

    /**
     * 更改feign日志默认为debug输出改为info输出
     * @return
     */
    @Bean
    Logger QjxFeign(){
        return new QjxFeignLogger();
    }

}
